var RunLayer6 = BaseLayer.extend({
	arr:null,
	scene:null,
	ctor:function (parent) {
		this._super(parent);
		this.init();
	},
	init:/**
			 * 初始化,
			 */
	function () {
		this._super();
		cc.log("RunLayer6初始化");
		
		// 天平
		this.balance = new Balance(this);
		this.balance.outFama();
		
		var beaker = new Beaker(this, 10, TAG_BEAKER4, this.callback); 
		beaker.setPosition(cc.p(350, 250));
		beaker.upLineResult();

		this.initIron();
		this.initLamp();
		
		// 物品库
		this.lib = new Lib(this);
		this.lib.init([TAG_LIB_POT, TAG_LIB_ROD, TAG_LIB_AIR, TAG_LIB_SPOON, TAG_LIB_ALCOHOL, TAG_LIB_PAPER2, TAG_LIB_WIDE]);
	},
	callback:function (p){
		var func = cc.callFunc(this.actionDone, this);
		switch(p.getTag()){
		case TAG_BEAKER4:
			if(gg.flow.flow.action == ACTION_DO2){
				// 倒到坩埚
				var move = cc.moveTo(0.7,cc.p(570,320));
				var rotate = cc.rotateTo(0.8, 90);
				var func = cc.callFunc(function(){
					p.pour2();
					p.hide(3, true);
				},this);
				var seq = cc.sequence(move, func, rotate);
				p.runAction(seq);
				// 隐藏铁架台
				if(this.ironNode != null){
					this.ironNode.runAction(cc.fadeTo(0.5,0));	
				}
			}
			break;
		case TAG_ROD:
			this.doRod(p);
			break;
		case TAG_AIR:
			this.loadAirSide();
			gg.flow.next();
			break;
		case TAG_PAPER2:
			if (gg.flow.flow.action == ACTION_DO1) {
				var move = cc.moveTo(0.5,cc.p(920,290));
				var seq = cc.sequence(move, func);
				p.runAction(seq);	
			} else if(gg.flow.flow.action == ACTION_DO2) {
				var move = cc.moveTo(0.5, cc.p(560, 280));
				var rotate = cc.rotateTo(0.5, 30);
				var delay = cc.delayTime(1.6);
				var fade = cc.fadeOut(0.5);
				var seq = cc.sequence(move, rotate, func, delay, fade);
				p.runAction(seq);	
			}
			break;
		case TAG_AIR_FUNNEL:
			var move = cc.moveTo(0.5, cc.p(530, 60));
			var rotate = cc.rotateTo(0.3,45);
			var rotate2 = cc.rotateTo(0.3,0);
			var move2 = cc.moveTo(0.5, cc.p(263, 165));
			var delay = cc.delayTime(3);
			var seq = cc.sequence(move , rotate, func, delay, rotate2, move2, this.callNext);
			p.runAction(seq);
			break;
		}
	},
	actionDone:function(p){
		var func = cc.callFunc(this.actionDone, this);
		switch(p.getTag()){
		case TAG_PAPER2:
			if(gg.flow.flow.action == ACTION_DO1){
				this.balance.showRider();
			} else if(gg.flow.flow.action == ACTION_DO2){
				// 用药匙刮
				var spoon = this.getChildByTag(TAG_SPOON);
				var move = cc.moveTo(0.5,cc.p(570,330));
				var moveSeq = cc.sequence(cc.moveBy(0.3,cc.p(40, -20)),cc.moveBy(0.3,cc.p(-40, 20)));
				var repeat = cc.repeat(moveSeq, 3);
				var delay = cc.delayTime(0.5);
				var move2 = cc.moveTo(0.5,cc.p(700,400));
				var fadeOut = cc.fadeOut(0.5);
				var seq = cc.sequence(move, repeat, cc.callFunc(function(){
					var wide = this.getChildByTag(TAG_WIDE_NODE);
					wide.addSalt(true);
				}, this), delay, move2, fadeOut);
				spoon.runAction(seq);
			}
			break;
		case TAG_AIR_FUNNEL:
			var spoon = this.getChildByTag(TAG_SPOON);
			var move = cc.moveTo(0.5,cc.p(710,280));
			var moveSeq = cc.sequence(cc.moveBy(0.3,cc.p(-30, -25)),cc.moveBy(0.3,cc.p(30, 25)));
			var repeat = cc.repeat(moveSeq, 3);
			var delay = cc.delayTime(0.5);
			var move2 = cc.moveTo(0.5,cc.p(700,400));
			var seq = cc.sequence(move, moveSeq, repeat, func, delay, move2);
			spoon.runAction(seq);
			break;
		case TAG_SPOON:
			// 纸上出现NaCl晶体
			var paper = this.getChildByTag(TAG_PAPER2);
			var salt = new cc.Sprite("#salt5.png");
			salt.setPosition(50,25);
			salt.setOpacity(0);
			paper.setCascadeOpacityEnabled(true);
			paper.addChild(salt);
			salt.runAction(cc.fadeTo(0.5, 255));

			var bushi = this.getChildByTag(TAG_AIR).getChildByTag(TAG_AIR_FUNNEL).getChildByTag(TAG_BUSHI_SALT);
			if(bushi != null){
				bushi.runAction(cc.fadeOut(0.5));	
			}
			break;
		}
	},
	doRod:/**
			 * 搅拌,蒸发、浓缩
			 * 
			 * @param p
			 */
		function(p){
		// 蒸发名冒烟
		this.getChildByTag(TAG_POT_NODE).smoking();
		// 搅拌浓缩,蒸发
		var rotate = cc.rotateTo(0.3, 45);
		var move = cc.moveTo(0.7,cc.p(620, 355));
		var moveSeq = cc.sequence(cc.moveBy(0.2,cc.p(60, 0)),cc.moveBy(0.2,cc.p(-60, 0)));
		var repeat = cc.repeat(moveSeq, 5);
		var move2 = cc.moveTo(0.7,cc.p(400,400));
		var rotate2 = cc.rotateTo(0.3, -45);
		var func = cc.callFunc(this.actionDone, this);
		var seq = cc.sequence(rotate,move, repeat, move2, rotate2, this.callNext,this.callKill);
		p.runAction(seq);
	},
	destroy:/**
			 * 销毁
			 */
	function(){
		this.lib.close();
		this._super();
	},
	onExit:function(){
		this._super();
	}
});